//
//  FSDisCoverFrameModel.m
//  fanshu
//
//  Created by mh on 16/3/28.
//  Copyright © 2016年 FS. All rights reserved.
//

#import "FSDisCoverFrameModel.h"

@implementation FSDisCoverFrameModel

- (void)setModel:(FSDiscoverArticleModel *)model{
    _model = model;
    if (self.cellHeight == 0) {
        CGFloat margin = 10;
        //头像
        CGFloat iconX = margin;
        CGFloat iconY = margin;
        CGFloat iconWH = 20;
        self.iconF = CGRectMake(iconX, iconY, iconWH, iconWH);
        //名称
        CGFloat nameX = CGRectGetMaxX(self.iconF) + (margin * 0.5);
        CGFloat nameY = iconY;
        CGFloat nameW = [model.name sizeWithFont:nameFont].width;
        CGFloat nameH = iconWH;
        self.nameF = CGRectMake(nameX, nameY, nameW, nameH);
        //发布时间
        CGFloat timeX = CGRectGetMaxX(self.nameF) + (margin * 0.5);
        CGFloat timeY = nameY;
        CGSize timeSize = [self.model.time sizeWithFont:timeFont];
        self.timeF = CGRectMake(timeX, timeY, timeSize.width, nameH);
        //配图
        CGFloat imageWH  = 80;
        CGFloat imageY  = CGRectGetMaxY(self.nameF);
        CGFloat imageX  = ScreenWidth - margin - imageWH;
        self.imageF = CGRectMake(imageX, imageY, imageWH, imageWH);
        //标题
        CGFloat titleX  = iconX;
        CGFloat titleY  = MAX(CGRectGetMaxY(self.iconF), CGRectGetMaxY(self.nameF)) + margin;
        CGFloat titleW  = ScreenWidth - imageWH - margin * 3;
        CGFloat titleH  = [self.model.title sizeWithFont:titleFont maxW:titleW].height;
        self.titleF = CGRectMake(titleX, titleY, titleW, titleH);
        //类型
        CGFloat typeX  = iconX;
        CGFloat typeY  = CGRectGetMaxY(self.titleF) + margin;
        CGSize typeSize = [self.model.type sizeWithFont:typeFont];
        CGFloat typeW = typeSize.width + margin;
        CGFloat typeH = typeSize.height + margin;
        self.typeF = CGRectMake(typeX, typeY, typeW, typeH);
        
        //多出来的几个字的宽度
        CGFloat defaultWidth = [[NSString stringWithFormat:@"阅读:"] sizeWithFont:countOfReadFont].width;
        
        //阅读数
        CGFloat countOfReadX  = CGRectGetMaxX(self.typeF) + margin;
        CGFloat countOfReadY  = typeY;
        CGFloat countOfReadW  = [self.model.countOfRead sizeWithFont:countOfReadFont].width + defaultWidth;
        CGFloat countOfReadH  = typeH;
        self.countOfReadF = CGRectMake(countOfReadX, countOfReadY, countOfReadW, countOfReadH);
        //评论数
        CGFloat countOfCommentX  = CGRectGetMaxX(self.countOfReadF) + margin;
        CGFloat countOfCommentY  = countOfReadY;
        CGFloat countOfCommentW  = [self.model.countOfComment sizeWithFont:countOfCommentFont].width + defaultWidth;
        CGFloat countOfCommentH  = countOfReadH;
        self.countOfCommentF = CGRectMake(countOfCommentX, countOfCommentY, countOfCommentW, countOfCommentH);
        //喜欢数
        CGFloat countOfLikeX  = CGRectGetMaxX(self.countOfCommentF) + margin;
        CGFloat countOfLikeY  = countOfCommentY;
        CGFloat countOfLikeW  = [self.model.countOfLike sizeWithFont:countOfLikeFont].width + defaultWidth;
        CGFloat countOfLikeH  = countOfCommentH;
        self.countOfLikeF = CGRectMake(countOfLikeX, countOfLikeY, countOfLikeW, countOfLikeH);
        
        //行高
        self.cellHeight = CGRectGetMaxY(self.typeF) + margin * 2;
    }
}

@end
